/**
 * Cs340 Fatboy Mafia Team
 */
package fatboy.hypeerweb;

import junit.framework.Assert;

/**
 * The Surface-Node State.  
 * A surface node must have a list of up (edge) pointers.  A surface node acts as a surrogate for edge nodes.
 * A surface node has no edgeNode children.  
 * A surface node has no active parent. 
 * (A surface node will have a height that is equal to the height of the "complete" hypercube.)
 *   
 * @author Ilya Vinogradov
 * 
 * @domain a singleton instance
 */
class SurfaceNodeState extends NodeState {

	public Node findInsertionPoint(Node thisNode) {
		Assert.assertTrue(thisNode.getPointers().size() > 0);
		
		Node edge = thisNode.getPointers().get(0).getNode();		
		Node interiorLower = edge.getParent(); //+1

		//System.out.println("low: " + interiorLower.getAddress() + ", high: " + thisNode.getAddress());
		Assert.assertTrue(interiorLower.getAddress().compareTo(thisNode.getAddress()) <= 0);
		
		return thisNode.findFirstChildlessInRange(interiorLower, thisNode);
	}
	
	protected Node getSurfaceOrLastNode(Node thisNode) {  
		
		return thisNode;
	}

	/* (non-Javadoc)
	 * @see fatboy.hypeerweb.Node#hasEdgeChild()
	 */
	public boolean hasEdgeChild(Node thisNode) {
		Assert.assertTrue(thisNode.getChild().getNodeType() != NodeType.EDGE_NODE);
		return false;
	}

	public boolean hasParent(Node thisNode) {
		return thisNode.getParent() != Node.nullNode;
	}

	public NodeAddress getFirstUpDownNodeAddress(Node thisNode) {
		return thisNode.getPointers().get(0).getNode().getAddress();
	}
	
	protected NodeType getType() {
		return NodeType.SURFACE_NODE;
	}

	@Override
	public void assertNodeStateIsCorrect(Node thisNode) {
		Assert.assertTrue(!thisNode.getPointers().isEmpty());
		//Assert.assertTrue(thisNode.getChild().getNodeType() == NodeType.NULL_NODE);
	}
}
